<template>
  <div class="home-container">
    <el-header>
      <div class="header-content">
        <h1>欢迎回来！</h1>
        <el-button type="danger" @click="handleLogout">退出登录</el-button>
      </div>
    </el-header>
    
    <el-main>
      <div class="welcome-section">
        <el-card>
          <template #header>
            <div class="card-header">
              <span>登录成功</span>
            </div>
          </template>
          <div class="welcome-content">
            <h2>欢迎使用 Vue 登录系统</h2>
            <p>您已成功登录系统！</p>
            <p>用户名：{{ username }}</p>
            <p>登录时间：{{ loginTime }}</p>
          </div>
        </el-card>
      </div>
    </el-main>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'

const router = useRouter()
const username = ref('admin')
const loginTime = ref('')

onMounted(() => {
  const token = localStorage.getItem('token')
  if (!token) {
    router.push('/login')
    return
  }
  
  loginTime.value = new Date().toLocaleString('zh-CN')
})

const handleLogout = () => {
  localStorage.removeItem('token')
  ElMessage.success('已退出登录')
  router.push('/login')
}
</script>

<style scoped>
.home-container {
  min-height: 100vh;
  background: #f5f7fa;
}

.el-header {
  background: white;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 20px;
}

.header-content h1 {
  margin: 0;
  color: #333;
}

.el-main {
  padding: 40px;
}

.welcome-section {
  max-width: 800px;
  margin: 0 auto;
}

.card-header {
  font-size: 18px;
  font-weight: bold;
}

.welcome-content {
  text-align: center;
  padding: 40px;
}

.welcome-content h2 {
  color: #333;
  margin-bottom: 20px;
}

.welcome-content p {
  color: #666;
  margin: 10px 0;
  font-size: 16px;
}
</style>